package logic

import (
	"context"

	"jinrigaoping/rpc/sys/internal/svc"
	"jinrigaoping/rpc/sys/sys"

	"github.com/zeromicro/go-zero/core/logx"
)

type SysRoleInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewSysRoleInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SysRoleInfoLogic {
	return &SysRoleInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *SysRoleInfoLogic) SysRoleInfo(in *sys.SysRoleInfoReq) (*sys.SysRoleInfoRes, error) {

	roleInfo, err := l.svcCtx.SysRoleModel.FindOne(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}

	//获取菜单id列表
	menuIds, err := l.svcCtx.SysMenuModel.FindMenuIdsByRoleId(l.ctx, in.Id)
	if err != nil {
		return nil, err
	}

	return &sys.SysRoleInfoRes{
		Id:         roleInfo.Id,
		RoleName:   roleInfo.RoleName,
		Remark:     roleInfo.Remark,
		MenuIdList: menuIds,
	}, nil
}
